#include "ringqueue.hpp"
#include <ctime>

using namespace std;

void* consumer(void* args)
{
    ringqueue<Task>* rq = static_cast<ringqueue<Task>*>(args);

    while(true)
    {
        Task tk;
        rq->push(tk);
        tk.run();
    }
}

void* productor(void* args)
{
    ringqueue<Task>* rq = static_cast<ringqueue<Task>*>(args);

    while(true)
    {
        int task = rand() % Task().cap();
        rq->push(Task(task));
    }
}

int main()
{
    srand(time(0));
    pthread_t c[2], p[2];
    ringqueue<Task>* rq = new ringqueue<Task>;

    pthread_create(&c[0], nullptr, consumer, rq);
    pthread_create(&c[1], nullptr, consumer, rq);

    pthread_create(&p[0], nullptr, productor, rq);
    pthread_create(&p[1], nullptr, productor, rq);

    pthread_join(c[0], nullptr);
    pthread_join(c[1], nullptr);

    pthread_join(p[0], nullptr);
    pthread_join(p[1], nullptr);

    delete rq;

    return 0;
}